Pirate Coves (1.1)
============
by lazygun

AI changed by Eric Walch.

1) The AI originally contained a message "NOT_FOUND" in the debris state. This was a type as the system sends "NOTHING_FOUND". This resulted in not recovering from this state and once the station discovered floating debris.

2) Then a merchants man was found it kept following him, even when it fled from scanner range. This is because Oolite is not sending a "TARGET_LOST" in this case. "TARGET_LOST" is only send when intercepting, attacking or fleeing. Because of this the cove released all its 5 pirate ships once a target was found.

3) Docking pirates were not added to the available defenders. Therefor it needs a role of "defense_ship" or "police". This is not a AI bug but lazygun added the launchPirate to the source code. Another Commander will change the source for Oolite 1.73 so launchPirate will launch pirates with defense_ship role.

4) In oolite 1.72 the message "CONDITION_GREEN" changed in "GREEN_ALERT". So with 1.72 it never received a save message and kept hanging in this state. It happened after releasing all its pirates not this bug had no big consequences. I added now both messages to let it work in old and new oolite.

5) Until 1.72 stations have no group ID set. Without this ID the groupAttack messages are not send to the launched pirates that do have a group ID set. I left the groupAttack command in as stations will probably get an group ID in Oolite 1.73.

6) As long as a station is yellow or red alert and is targeting a ship, it will be seen as hostile to that ship. Traders scan for hostile ships and will attack such a station. At first the station is launching pirates by itself and those will start fighting the trader. But the trader might already have send escorts to attack. Those are not found by the pirates and the groupAttack from the station is not received by the pirates. And when the station had already send out a pirates that have returned, the station can not set them again. This will be fixed with 1.73.
But to prevent this I made sure the station is only briefly targeting the target to send a groupAttack message and that switches target to system station. (AI can't set target to none so setting to main station is the best alternative). Traders scan for hostiles every 10 seconds so they will never see the station.

7) Pirates don't need a target on launch as their AI looks for their own target and ignores the one the have on launch.

8) I rearranged the states now in a way it is only briefly in the ATTACK state. When there are no hostiles it will only launch a single pirate and return to IDLE state. When there are hostiles it will go in red alert and launch a second pirate. And when attacked it will keep launching pirates. In defence way it is at least as aggressive as it was. In offensive way it could be a bit friendlier than before. It does not keep launching pirates when the target left the scanner and when the target stays on scanner the interval between launches it a bit longer.